//
//  CMDateFormatterType.swift
//  TTCOM
//
//  Created by Toj on 8/1/22.
//

/*
 * 日期格式化字符串
 a: AM/ PM (上午ante meridiem/ 下午post meridiem)
 A: 0~86399999 (第一天的第多少毫秒)
 
 c/cc: 1~7 (星期几)
 ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
 cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
 
 d: 1~31 (0 padded Day of Month)
 D: 1~366 (0 padded Day of Year)
 
 e: 1~7 (0 padded Day of Week)
 E~EEE: Sun/Mon/Tue/Wed/Thu/Fri/Sat
 EEEE: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
 
 F:    1~5 (0 padded Week of Month, first day of week = Monday)
 
 g:    Julian Day Number (number of days since 4713 BC January 1)
 G~GGG:    BC/AD (Era Designator Abbreviated)
 GGGG:    Before Christ/Anno Domini
 
 h:    1~12 (0 padded Hour (12hr))
 H:    0~23 (0 padded Hour (24hr))
 
 k:    1~24 (0 padded Hour (24hr)
 K:    0~11 (0 padded Hour (12hr))
 
 L/LL:    1~12 (0 padded Month)
 LLL:    Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec
 LLLL: January/February/March/April/May/June/July/August/September/October/November/December
 
 m:    0~59 (0 padded Minute)
 M/MM:    1~12 (0 padded Month)
 MMM:    Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec
 MMMM: January/February/March/April/May/June/July/August/September/October/November/December
 
 q/qq:    1~4 (0 padded Quarter)
 qqq:    Q1/Q2/Q3/Q4
 qqqq:    1st quarter/2nd quarter/3rd quarter/4th quarter
 Q/QQ:    1~4 (0 padded Quarter)
 QQQ:    Q1/Q2/Q3/Q4
 QQQQ:    1st quarter/2nd quarter/3rd quarter/4th quarter
 
 s:    0~59 (0 padded Second)
 S:    (rounded Sub-Second)
 T:    日期 和 时间 合并表示时, 要在时间前面加一大写字母T, 占位
 u:    (0 padded Year)
 
 v~vvv:    (General GMT Timezone Abbreviation)
 vvvv:    (General GMT Timezone Name)
 
 w:    1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of year starts from the last Sunday of last year)
 W:    1~5 (0 padded Week of Month, 1st day of week = Sunday)
 
 y/yyyy:    (Full Year)
 yy/yyy:    (2 Digits Year)
 Y/YYYY:    (Full Year, starting from the Sunday of the 1st week of year)
 YY/YYY:    (2 Digits Year, starting from the Sunday of the 1st week of year)
 
 z~zzz:    (Specific GMT Timezone Abbreviation)
 zzzz:    (Specific GMT Timezone Name)
 Z:    +0000 (RFC 822 Timezone)
 */

/**
 * 日期格式化字符串
 * 符号  备注                  e.g.
 * a: Am/pm                 下午
 * A: 第一天的第多少毫秒       [0, 86399999]
 * c: 星期几                 [1, 7]
 * cc: 星期几                [1, 7]
 * ccc: 星期几               Sun/Mon/Tue/Wed/Thu/Fri/Sat
 * cccc: 星期几              Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
 * D: 该年的第几天            351
 * d: 该月的第几天            16
 * E: 周几                   周三
 * e: 该周的第几天            4
 * F: 该月的第几星期           3
 * g:
 * G:   Era标志符              公元
 * GG:
 * GGG:
 * GGGG:
 * H:   一天的第几小时（0-23）   15
 * h:   am/pm的第几小时（1-12）  3
 * k:   一天的第几小时（1-24）   15
 * K:   am/pm的第几小时（0-11）  3
 *
 * y:   年份                   2020
 * Y:
 * M:   该年的第几月            12
 * w:   该年的第几周            51
 * W:   该月的第几周            3
 * Q:   第几季度                4
 * q:
 * m:   该小时的第几分钟         19
 * s:   该分钟的第几秒           55
 * S:   该秒的第几毫秒           978
 * z:   时区                   GMT+8
 * Z:   时区                   +0800
 */

import Foundation

public struct NSFormatSymbol {
    public var rawValue: String
    
    public static let backslash: Self = NSFormatSymbol(rawValue: "/")
    public static let slash: Self = NSFormatSymbol(rawValue: "\\")
    
    public static let dot: Self = NSFormatSymbol(rawValue: ".")
    public static let across: Self = NSFormatSymbol(rawValue: "-")
    public static let underline: Self = NSFormatSymbol(rawValue: "_")
}

public enum NSDateFormatType: String {
    case yyyyMMdd = "yyyy-MM-dd"
    case yyyyMMddh  = "yyyy-MM-dd h"
    case yyyyMMddHH = "yyyy-MM-dd HH"
    case yyyyMMddhmm  = "yyyy-MM-dd h:mm"
    case yyyyMMddHHmm = "yyyy-MM-dd HH:mm"
    case yyyyMMddhmmss  = "yyyy-MM-dd h:mm:ss"
    case yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"
    case yyyyMMddThmmssZ  = "yyyy-MM-dd'T'h:mm:ss'Z'"
    case yyyyMMddTHHmmssZ = "yyyy-MM-dd'T'HH:mm:ss'Z'"
    
    case Mdyyyy = "M-d-yyyy"
    case MMMdyyyy = "MMM-d-yyyy"
    case MMMMdyyyy = "MMMM-d-yyyy"
    case MMMMdyyyyHHmmss = "MMMM-d-yyyy HH:mm:ss"
    
    public var string: String { return rawValue }
    public var to_string: String { return rawValue }
    
    public func replaceSymbol(symbol: NSFormatSymbol) -> String {
        return replaceSymbol(replaced: symbol.rawValue)
    }
    
    public func replaceSymbol(replaced: String) -> String {
        return string.cm_replace(NSFormatSymbol.across.rawValue, replaced)
    }
}
